package com.excel.validators.core.decorative;

import com.excel.validators.core.decorative.inner.IErrorMessage;

/**
 * @author wangxiaoliang10
 *
 * 2017年8月5日
 * 
 * 爱审计对象，主要用来包装单元格数据
 */
public class FieldValue<V> extends LiveExpression<V> implements IErrorMessage {

	/**
	 * filedName
	 */
	private String fieldName;
	
	/**
	 * error message of validation
	 */
	private StringBuilder error;
	
	public FieldValue(String fieldName ,String oleValue,Object newValue) {
			super(oleValue,newValue);
			this.fieldName = fieldName;
	}

	/**
	 * set error message
	 */
	public void setMessage(String message) {
			if (error == null) {
					error = new StringBuilder();
			}
			// structured sentence for error message
			error.append(message);
	}

	@Override
	public String getMessage() {
			if (error != null) {
					return error.toString();
			}
			return null;
	}
	
	/**
	 * get error flag
	 * @return
	 */
	@Override
	public boolean hasError() {
			return error != null;
	}

	public String getFieldName() {
			return fieldName;
	}
	
}
